<?php
namespace app\serveruser\service\auth;

use \app\manage\service\ApiBase;

/**
 * 对角色组管理的操作
 * @author adv30 <adv30@126.com> 2017年6月1日16:49:58
 */
class RoleGroup extends ApiBase
{
    protected $roleGroupValidate = '\app\serveruser\validate\RoleGroup';
    protected $roleGroupLogic = '\app\serveruser\logic\RoleGroup';
    // 增加一个角色组
    public function add(): array
    {
        $data = $this->haveIssetReceiveData(['name' => ' ', 'role_ids' => ' ']);
        return $this->stepRun($data, 'add', 'add');
    }
    // 禁用一个角色组
    public function stop(): array
    {
        $data = $this->issetReceiveData(['id' => '0', 'name' => ' ']);
        return $this->stepRun($data, 'stop', 'stop');
    }
    // 获取角色组列表分页数据
    public function list(): array
    {
        $data = $this->haveIssetReceiveData(['page' => 1, 'list_rows' => '']);
        return $this->stepRun($data, 'list', 'list');
    }
    // 修改角色组资料
    public function edit(): array
    {
        $data['id'] = $this->arrData['id'];
        if (isset($this->arrData['name']) || isset($this->arrData['role_ids'])) {
            isset($this->arrData['name']) ? $data['name'] = $this->arrData['name'] : null;
            isset($this->arrData['role_ids']) ? $data['role_ids'] = $this->arrData['role_ids'] : null;
        } else {
            return verify_err($data, 'name,role_ids参数至少要传一个');
        }
        return $this->stepRun($data, 'edit', 'edit');
    }
    // 将roleGroupIds解释成role_ids
    public function roleGroupIdsToRoleIds(): array
    {
        $data = $this->haveIssetReceiveData(['group_ids' => '0']);
        if ('0' === $data['group_ids']) {
            return verify_err(null, '请传ids参数');
        };
        return $this->stepRun($data, 'roleGroupIdsToRoleIds', 'roleGroupIdsToRoleIds');
    }
}
